package com.cjl.learn.bean;

import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Value;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

/**
 * Created by Enzo Cotter on 2019-07-21.
 */
public class Bird implements InitializingBean, DisposableBean {

    @Value("${name}")
    private String name;

    public Bird() {
        System.out.println(this.name);
        System.out.println("Bird...constructor");
    }

    public void initMethod() {
//        this.name = "moni";
        System.out.println("Bird...initMethod");
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        System.out.println(this.name);
        System.out.println("Bird...afterPropertiesSet");
    }

    @Override
    public void destroy() throws Exception {
        System.out.println("Bird...destroy");
    }

    @PostConstruct
    public void postConstruct() {
        System.out.println(this.name);
        System.out.println("Bird...postConstruct");
    }

    @PreDestroy
    public void preDestroy() {
        System.out.println("Bird...preDestroy");
    }

    public void destroyMethod() {
        System.out.println("Bird...destroyMethod");
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Override
    public String toString() {
        return "Bird{" +
                "name='" + name + '\'' +
                '}';
    }
}
